Skip to content

Conversation

zry656565
Copy link
Contributor

  • simplify the implement of useObservable.

Copy link
Contributor

@Brooooooklyn Brooooooklyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@Brooooooklyn Brooooooklyn merged commit 9ab9091 into master Nov 17, 2018
@Brooooooklyn Brooooooklyn deleted the update-use-observable branch November 17, 2018 14:57
@TotooriaHyperion
Copy link

@Brooooooklyn this instantiate a Subject every render(first mount & update). It's not performant.
Not sure whether it's better to change code here or open an issue to react for using a callback to return the initial state.

const [state] = setState(() => new BehaviorSubject());

@zry656565
Copy link
Contributor Author

It seems that this pattern has been implemented internally.
https://github.com/facebook/react/blob/master/packages/react-reconciler/src/ReactFiberHooks.js#L337

@zry656565
Copy link
Contributor Author

but I guess the cost of initializing a function every render is quite same as initializing a BehaviorSubject. Not very sure about it, need some more tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants